package pl.nazaweb.imedproplus.model.entity;

import pl.nazaweb.imedproplus.model.interfaces.IInstitution;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "institution")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Institution.findAll", query = "SELECT i FROM Institution i"),
    @NamedQuery(name = "Institution.findById", query = "SELECT i FROM Institution i WHERE i.id = :id"),
    @NamedQuery(name = "Institution.findByName", query = "SELECT i FROM Institution i WHERE i.name = :name"),
    @NamedQuery(name = "Institution.findByStreet", query = "SELECT i FROM Institution i WHERE i.street = :street"),
    @NamedQuery(name = "Institution.findByCity", query = "SELECT i FROM Institution i WHERE i.city = :city"),
    @NamedQuery(name = "Institution.findByPost", query = "SELECT i FROM Institution i WHERE i.post = :post"),
    @NamedQuery(name = "Institution.findByPostCode", query = "SELECT i FROM Institution i WHERE i.postCode = :postCode"),
    @NamedQuery(name = "Institution.findByRegon", query = "SELECT i FROM Institution i WHERE i.regon = :regon"),
    @NamedQuery(name = "Institution.findByPhone", query = "SELECT i FROM Institution i WHERE i.phone = :phone"),
    @NamedQuery(name = "Institution.findByNip", query = "SELECT i FROM Institution i WHERE i.nip = :nip")})
public class Institution implements Serializable, IInstitution {
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "institution_sequence_", sequenceName = "institution_sequence", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "institution_sequence_")
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 250)
    @Column(name = "name")
    private String name;
    @Size(max = 250)
    @Column(name = "street")
    private String street;
    @Size(max = 250)
    @Column(name = "city")
    private String city;
    @Size(max = 250)
    @Column(name = "post")
    private String post;
    @Size(max = 6)
    @Column(name = "post_code")
    private String postCode;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "regon")
    private String regon;
    // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
    @Size(max = 250)
    @Column(name = "phone")
    private String phone;
    @Size(max = 11)
    @Column(name = "nip")
    private String nip;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "institution")
    private List<Referral> referralList;

    public Institution() {
    }

    public Institution(Long id) {
        this.id = id;
    }

    public Institution(Long id, String name, String regon) {
        this.id = id;
        this.name = name;
        this.regon = regon;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getStreet() {
        return street;
    }

    @Override
    public void setStreet(String street) {
        this.street = street;
    }

    @Override
    public String getCity() {
        return city;
    }

    @Override
    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String getPost() {
        return post;
    }

    @Override
    public void setPost(String post) {
        this.post = post;
    }

    @Override
    public String getPostCode() {
        return postCode;
    }

    @Override
    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    @Override
    public String getRegon() {
        return regon;
    }

    @Override
    public void setRegon(String regon) {
        this.regon = regon;
    }

    @Override
    public String getPhone() {
        return phone;
    }

    @Override
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String getNip() {
        return nip;
    }

    @Override
    public void setNip(String nip) {
        this.nip = nip;
    }

    @XmlTransient
    @Override
    public List<Referral> getReferralList() {
        return referralList;
    }

    @Override
    public void setReferralList(List<Referral> referralList) {
        this.referralList = referralList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Institution)) {
            return false;
        }
        Institution other = (Institution) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.nazaweb.imedproplus.model.entity.Institution[ id=" + id + " ]";
    }

}
